from django_filters.filterset import FilterSet
from django_filters import filters
from . import models


class CourseFilterSet(FilterSet):
    # 区间过滤：field_name关联的Model字段；lookup_expr设置规则；
    # gt是大于；gte是大于等于;
    # 课程的价格范围要大于等于min_price,小于max_price
    # 前端使用：
    # http://127.0.0.1:8000/course/free/?course_category=1&min_price=90&max_price=100
    min_price = filters.NumberFilter(
        field_name='price',
        lookup_expr='gte'
    )
    max_price = filters.NumberFilter(
        field_name='price',
        lookup_expr='lte'
    )

    class Meta:
        model = models.Course
        fields = ['course_category', 'min_price', 'max_price']


